<?php
class SocializrSession {
  protected static $instance = null;  // das einzige Objekt dieser Klasse
  
  public static function getInstance()
  {
    if(null === self::$instance)
    {
      self::$instance = new SocializrSession();
    }

    return self::$instance;
  }
  
  public function getAttribute($name)
  {
    if(class_exists('ZendRegistry'))
    {
      $session = Zend_Registry::get('session');
      return $session->$name;
    }
    elseif(class_exists('sfContext'))
    {
      return sfContext::getInstance()->getUser()->getAttribute($name);
    }
    else return $_SESSION[$name];
  }
  
  public function setAttribute($name, $value)
  {
    if(class_exists('ZendRegistry'))
    {
      $session = Zend_Registry::get('session');
      $session->$name = $value;
    }
    elseif(class_exists('sfContext'))
    {
      return sfContext::getInstance()->getUser()->setAttribute($name, $value);
    }
    else $_SESSION[$name] = $value;
  }
  
  protected function __construct() {}
  
  /**
   * Instanzieren durch die Hintertür verhindern.
   *
   */
  private function __clone() {}  
}
?>